package com.aspose.cells;

import java.util.ArrayList;
import java.util.Iterator;

class zjp {
   private int b;
   private ChartCollection c;
   private Chart d;
   private zqa e;
   private ArrayList f;
   boolean a;
   private int g;
   private WorksheetCollection h;
   private static final com.aspose.cells.b.c.a.za i = new com.aspose.cells.b.c.a.za(new String[]{"#N/A", "#DIV/0!", "#NAME?", "#NULL!", "#NUM!", "#REF!", "#VALUE!"});

   static byte[] a(Font var0, int var1, int var2, int var3, int var4, int var5) {
      int var6 = var0.getName().length();
      int var7 = 32 + var6 * 2;
      byte[] var8 = new byte[var7];
      System.arraycopy(Encoding.getUnicode().a(var0.getName()), 0, var8, 0, var6 * 2);
      System.arraycopy(com.aspose.cells.b.a.zc.a(var0.i()), 0, var8, var6, 4);
      int var9 = var6 + 4;
      if (var0.isBold()) {
         var8[var9] = (byte)(var8[var9] | 1);
      }

      if (var0.isItalic()) {
         var8[var9] = (byte)(var8[var9] | 2);
      }

      if (var0.getUnderline() != 0) {
         var8[var9] = (byte)(var8[var9] | 4);
      }

      if (var0.isStrikeout()) {
         var8[var9] = (byte)(var8[var9] | 128);
      }

      var8[var9 + 1] = 1;
      if (var0.getDoubleSize() * 96.0D / 72.0D < 6.0D) {
         var8[var9 + 1] = (byte)(var8[var9 + 1] | 2);
      }

      var9 += 2;
      System.arraycopy(com.aspose.cells.b.a.zc.a(var0.g()), 0, var8, var9, 2);
      var9 += 2;
      var8[var9] = var0.e();
      var9 += 2;
      switch(var0.getUnderline()) {
      case 1:
         var8[var9] = 1;
         break;
      case 2:
         var8[var9] = 2;
         break;
      case 3:
         var8[var9] = 33;
         break;
      case 4:
         var8[var9] = 34;
      }

      ++var9;
      var8[var9++] = var0.h();
      var8[var9++] = (byte)var0.getCharset();
      ++var9;
      Color var10 = var0.getColor();
      var8[var9++] = var10.getR();
      var8[var9++] = var10.getG();
      var8[var9++] = var10.getB();
      ++var9;
      System.arraycopy(com.aspose.cells.b.a.zc.a(var1), 0, var8, var9, 4);
      var9 += 4;
      var8[var9++] = (byte)var2;
      System.arraycopy(com.aspose.cells.b.a.zc.a(var3), 0, var8, var9, 4);
      var9 += 4;
      System.arraycopy(com.aspose.cells.b.a.zc.a(var4), 0, var8, var9, 4);
      var9 += 4;
      var8[var9++] = (byte)var5;
      return var8;
   }

   zjp(WorksheetCollection var1, int var2, ChartCollection var3, zqa var4) {
      this.b = var1.l();
      this.c = var3;
      this.e = var4;
      this.h = var1;
      this.g = var2;
      this.b();
   }

   private void b() {
      if (this.c.getCount() != 0) {
         Worksheet var1 = this.h.get(this.g);
         switch(var1.getType()) {
         case 1:
            Iterator var2 = this.c.iterator();

            while(var2.hasNext()) {
               Chart var3 = (Chart)var2.next();
               b(var3);
            }

            return;
         case 2:
            b(this.c.get(0));
         }

      }
   }

   private static void a(Chart var0, zik var1, int var2, zqa var3) throws Exception {
      if (var1 != null) {
         if (var1.q() == 1 || var1.q() == 6 || !var1.a() || zyo.a(var1.f(), -1, -1, (WorksheetCollection)var0.j())) {
            ArrayList var4 = var1.d();
            if (var4 != null && var4.size() != 0) {
               int var5 = var1.q();
               zakt var6 = new zakt();
               zapd var7 = new zapd();

               for(int var8 = 0; var8 < var4.size(); ++var8) {
                  if (var4.get(var8) instanceof String) {
                     String var9 = (String)var4.get(var8);
                     if (zsk.c(var9)) {
                        zcy var10 = new zcy();
                        byte var11 = 0;
                        switch(i.a(var9)) {
                        case 0:
                           var11 = 42;
                           break;
                        case 1:
                           var11 = 7;
                           break;
                        case 2:
                           var11 = 29;
                           break;
                        case 3:
                           var11 = 0;
                           break;
                        case 4:
                           var11 = 36;
                           break;
                        case 5:
                           var11 = 23;
                           break;
                        case 6:
                           var11 = 15;
                        }

                        var10.a(var8, (byte)var2, 0, var11, false);
                        var10.a(var3);
                     } else if ("".equals(var9)) {
                        zcu var12 = new zcu(var8, (byte)var2, 0);
                        var12.a(var3);
                     } else {
                        var6.a(var8, var2, 0, (String)var4.get(var8));
                        var6.a(var3);
                     }
                  } else if (var4.get(var8) instanceof Double) {
                     var7.a(var8, var2, 0, (Double)var4.get(var8));
                     var7.a(var3);
                  }
               }

            }
         }
      }
   }

   void a(Chart var1) throws Exception {
      this.d = var1;
      this.g();
      zayj var2 = new zayj();
      var2.a((byte)10);
      var2.a(this.e);
      var1.a(this.e);
      zavk var3 = new zavk(var1.getPrintSize());
      var3.a(this.e);
      this.e.a(new byte[]{18, 0, 2, 0, 0, 0});
      this.e.a(new byte[]{1, 16, 2, 0, 0, 0});
      Iterator var5;
      if (this.h.get(this.g).getType() == 2) {
         Object var4 = this.h.get(this.g).z();
         if (var4 != null) {
            if (var4 instanceof ArrayList) {
               var5 = ((ArrayList)var4).iterator();

               while(var5.hasNext()) {
                  byte[] var6 = (byte[])var5.next();
                  this.e.a(var6);
               }
            } else if (var4 instanceof byte[]) {
               zcd var14 = new zcd();
               var14.a((byte[])((byte[])var4));
               var14.a(this.e);
            }
         }
      }

      if (var1.B() != null && var1.B().size() != 0) {
         zuw var11 = new zuw();
         var5 = var1.B().iterator();

         while(var5.hasNext()) {
            zbi var18 = (zbi)var5.next();
            var11.a(var18);
            var11.a(this.e);
         }
      }

      if (var1.getPivotSource() != null && !"".equals(var1.getPivotSource())) {
         zayp var12 = new zayp();
         String var17 = var1.getPivotSource();
         if (var17.indexOf(91) == -1) {
            var17 = "[Aspose.xls]" + var17;
         }

         var12.a(var17);
         var12.a(this.e);
         zayq var19 = new zayq();
         var19.a(var1.getHidePivotFieldButtons());
         var19.a(this.e);
      }

      if (var1.l() != null && var1.l().getCount() != 0) {
         zant var13 = new zant(this.h, this.h.get(this.g), var1.getShapes(), this.e);
         var13.a();
      }

      this.i();
      this.f();
      this.c();
      if (this.h.get(this.g).getType() == 2) {
         String var15 = this.h.get(this.g).k;
         if (var15 != null && !"".equals(var15)) {
            zkb var20 = new zkb();
            var20.a(var15);
            var20.a(this.e);
         }

         if (!this.h.get(this.g).j.a()) {
            int var22 = this.h.get(this.g).v();
            if (var22 != 64) {
               zbmf var21 = new zbmf(var22, this.h.get(this.g).j);
               var21.a(this.e);
            } else if (var22 == 64) {
               Worksheet var23 = this.h.get(this.g);
               int var7 = var23.j.a(var23.getWorkbook());
               int var8 = var23.c().m().c(var7);
               int var9 = var23.c().m().b(var8);
               zbmf var10 = new zbmf(var8, var9, var23.j);
               var10.a(this.e);
            }
         }
      }

      if (this.d.e() != null) {
         Iterator var16 = var1.b().iterator();

         while(var16.hasNext()) {
            byte[] var24 = (byte[])var16.next();
            this.e.a(var24);
         }
      }

      this.h();
      this.d.a(false);
   }

   private void c() throws Exception {
      if (this.h.get(this.g).getType() == 2 && this.d == this.h.get(this.g).getCharts().get(0)) {
         this.e.c(574);
         this.e.c(10);
         if (this.g == this.h.getActiveSheetIndex()) {
            this.e.c(1538);
         } else {
            this.e.c(2);
         }

         this.e.a((int)0);
         this.e.a((int)0);
         this.m();
      }
   }

   private void d() throws Exception {
      int var1;
      for(var1 = 0; var1 < this.d.getNSeries().getCount(); ++var1) {
         zik var2 = this.d.getNSeries().get(var1).l();
         a(this.d, var2, var1, this.e);
      }

      if (this.f != null && this.f.size() > this.d.getNSeries().getCount()) {
         for(var1 = this.d.getNSeries().getCount(); var1 < this.f.size(); ++var1) {
            zhr var4 = (zhr)this.f.get(var1);
            if (var4.b == 2) {
               ErrorBar var3 = (ErrorBar)var4.a;
               if (var3.a()) {
                  if (var4.c) {
                     a(this.d, var3.b(), var1, this.e);
                  } else {
                     a(this.d, var3.c(), var1, this.e);
                  }
               }
            }
         }
      }

   }

   private void e() throws Exception {
      int var1;
      for(var1 = 0; var1 < this.d.getNSeries().getCount(); ++var1) {
         zik var2 = this.d.getNSeries().get(var1).m();
         a(this.d, var2, var1, this.e);
      }

      if (this.f != null && this.f.size() > this.d.getNSeries().getCount()) {
         for(var1 = this.d.getNSeries().getCount(); var1 < this.f.size(); ++var1) {
            zhr var4 = (zhr)this.f.get(var1);
            if (var4.b == 2) {
               ErrorBar var3 = (ErrorBar)var4.a;
               if (!var3.a()) {
                  if (var4.c) {
                     a(this.d, var3.b(), var1, this.e);
                  } else {
                     a(this.d, var3.c(), var1, this.e);
                  }
               }
            }
         }
      }

   }

   void a() throws Exception {
      if (ChartCollection.q(this.d.getType())) {
         for(int var1 = 0; var1 < this.d.getNSeries().getCount(); ++var1) {
            zik var2 = this.d.getNSeries().get(var1).n();
            a(this.d, var2, var1, this.e);
         }

      }
   }

   private void f() throws Exception {
      zbbo var1 = new zbbo((byte)2);
      var1.a(this.e);
      this.e();
      var1 = new zbbo((byte)1);
      var1.a(this.e);
      this.d();
      var1 = new zbbo((byte)3);
      var1.a(this.e);
      this.a();
   }

   private void g() throws Exception {
      zca var1 = new zca(2, this.h.l());
      var1.a(this.e);
   }

   private void h() throws Exception {
      zrx var1 = new zrx();
      var1.a(this.e);
   }

   private void i() throws Exception {
      zbu var1 = new zbu(this.h, this.g, this.d, this, this.e);
      boolean var2 = var1.c();
      this.l();
      this.e.a((int)4147);
      if (this.d.b != null) {
         for(int var3 = 0; var3 < this.d.b.size(); ++var3) {
            byte[] var4 = (byte[])((byte[])this.d.b.get(var3));
            this.e.a(var4);
         }
      }

      var1.a(this.d.getValueAxis(), this.d.getSecondValueAxis());
      this.m();
      this.n();
      if (this.d.getChartArea().getBorder().isVisible() || this.d.getChartArea().getArea().getFormatting() != 1 || !this.d.isRectangularCornered()) {
         this.d.getChartArea().getArea().setInvertIfNegative(!this.d.isRectangularCornered());
         this.a(this.d.getChartArea(), true);
      }

      zaoc var10 = new zaoc(this.e, this.h, this.g, this.d);
      this.f = var10.a();
      this.a((short)2);
      this.a((short)3);
      var1.a();
      PlotArea var11 = this.d.getPlotArea();
      boolean var5 = (this.d.h() & 255 & 16) != 0;
      if (var11.p != null) {
         boolean var6 = (this.d.h() & 255 & 8) != 0;
         if (var6 == var5) {
            var11.p[12] = 1;
         } else {
            var11.p[12] = 0;
         }

         zmz var7 = new zmz();
         var7.b(var11.p);
         var7.a(this.e);
      }

      this.k();
      if (this.d.getShowDataTable()) {
         this.j();
      }

      var10.a(this.d);
      PlotArea var12 = this.d.getPlotArea();
      boolean var13 = (this.d.h() & 255 & 16) != 0;
      if (var12.p != null && !var13) {
         boolean var8 = (this.d.h() & 255 & 8) != 0;
         if (var8 == var13) {
            var12.p[12] = 1;
         } else {
            var12.p[12] = 0;
         }

         zmz var9 = new zmz();
         var9.b(var12.p);
         var9.a(this.e);
      }

      if (this.a) {
         zaym var14 = new zaym();
         var14.a(13, 0, 0, 0);
         var14.a(this.e);
         this.a = false;
      }

      this.e.a((int)4148);
   }

   private void a(Font var1, int var2, int var3, ArrayList var4) throws Exception {
      if (var1 != null || var2 != -1) {
         if (var1 != null) {
            var2 = var1.j();
         }

         if (var4 != null) {
            zd var5 = new zd();
            int var6 = var5.a(var3, var2, var4);
            zxs var7;
            if (var6 == -1) {
               var7 = new zxs(var2);
               var7.a(this.e);
               var5.a(this.e);
            } else {
               var7 = new zxs(var6);
               var7.a(this.e);
            }
         } else {
            zxs var8 = new zxs(var2);
            var8.a(this.e);
         }

      }
   }

   private void j() throws Exception {
      ChartDataTable var1 = this.d.getChartDataTable();
      znk var2 = new znk();
      if (var1 != null) {
         var2.a(var1);
      }

      var2.a(this.e);
      this.e.a((int)4147);
      zale var3 = new zale(this.b);
      var3.a();
      var3.a(this.e);
      this.e.a((int)4147);
      Font var4 = null;
      if (this.d.q() != null) {
         var4 = this.d.q().a();
      }

      zbsv var5 = new zbsv(this.b);
      var5.a(var4);
      if (this.d.q() != null) {
         var5.a(this.d.q().getBackgroundMode());
      }

      var5.a((zqa)this.e);
      this.e.a((int)4147);
      this.a(var4, var1.b(), 0, (ArrayList)null);
      zc var6 = new zc();
      var6.a();
      var6.a(this.e);
      this.e.a((int)4148);
      if (var1 != null && var1.c() != null && !var1.c().isAuto()) {
         zabj var7 = new zabj((byte)3);
         var7.a(this.e);
         this.e.a((int)4147);
         zalx var8 = new zalx(this.h.l(), this.h.m());
         var8.a(var1.getBorder(), false);
         var8.a(this.e);
         zaw var9 = new zaw(this.h.l(), this.h.m());
         var9.a(this.e);
         this.e.a((int)4148);
      }

      this.e.a((int)4148);
      this.e.a((int)4148);
   }

   private void k() throws Exception {
      Title var1 = this.d.n();
      if (var1 != null) {
         zbsv var2 = new zbsv(this.b);
         var2.a(var1);
         var2.a((zqa)this.e);
         this.e.a((int)4147);
         zavg var3;
         if (var1.getText() != null && !"".equals(var1.getText())) {
            var3 = new zavg(false);
            var3.a(var1);
            var3.a((zqa)this.e);
            this.a(var1.g(), var1.h(), var1.getText().length(), var1.D());
            zc var5 = new zc();
            var5.a(var1.x);
            var5.a(this.e);
            zbcw var7 = new zbcw(this.b, var1.getText());
            var7.a(this.e);
         } else {
            var3 = new zavg(false);
            var3.a(var1);
            var3.a((zqa)this.e);
            this.a(var1.g(), var1.h(), 0, (ArrayList)null);
            zc var4 = new zc();
            var4.a(var1.x);
            var4.a(this.e);
         }

         if (!var1.E() && var1.H()) {
            this.a(var1, false);
         }

         zarz var6 = new zarz();
         var6.a((byte)1);
         var6.a(this.e);
         this.e.a((int)4148);
      }
   }

   private void l() throws Exception {
      zjj var1 = new zjj(this.d);
      var1.a(this.e);
   }

   private void m() throws Exception {
      if (this.h.get(this.g).getType() != 2) {
         this.e.c(160);
         this.e.c(4);
         this.e.a(65537);
      } else {
         zbbl var1 = new zbbl(this.h.get(this.g).getZoom());
         var1.a(this.e);
      }

   }

   private void n() throws Exception {
      byte[] var1 = new byte[12];
      var1[0] = 100;
      var1[1] = 16;
      var1[2] = 8;
      byte var2 = 4;
      double var3 = 0.0D;
      var3 = this.d.D();
      if (var3 - (double)((int)var3) != 0.0D) {
         System.arraycopy(com.aspose.cells.b.a.zc.a((int)((var3 - (double)((int)var3)) * 65536.0D)), 0, var1, var2, 2);
      }

      System.arraycopy(com.aspose.cells.b.a.zc.a((int)var3), 0, var1, var2 + 2, 2);
      int var5 = var2 + 4;
      var3 = this.d.E();
      if (var3 - (double)((int)var3) != 0.0D) {
         System.arraycopy(com.aspose.cells.b.a.zc.a((int)((var3 - (double)((int)var3)) * 65536.0D)), 0, var1, var5, 2);
      }

      System.arraycopy(com.aspose.cells.b.a.zc.a((int)var3), 0, var1, var5 + 2, 2);
      var5 += 4;
      this.e.a(var1);
   }

   private void a(ChartFrame var1, boolean var2) throws Exception {
      zabj var3;
      if (var2) {
         var3 = new zabj((byte)2);
      } else if (var1.l() && var1.i()) {
         var3 = new zabj((byte)3);
      } else if (var1.i()) {
         var3 = new zabj((byte)2);
      } else if (var1.l()) {
         var3 = new zabj((byte)3);
      } else {
         var3 = new zabj((byte)2);
      }

      var3.a(var1);
      var3.a(this.e);
      this.e.a((int)4147);
      zalx var4 = new zalx(this.b, this.h.m());
      var4.a(var1.getBorder(), false);
      var4.a(this.e);
      this.a(var1.getArea());
      if (var2 && var1.a != null) {
         zayl var5 = new zayl();
         var5.a(13, 0, 0, 0);
         var5.a(this.e);
         this.a = true;
         zayl var6 = new zayl();
         var6.a(7, 2, 0, 0);
         var6.a(this.e);
         zbjp var7 = new zbjp();
         var7.a(var1.a);
         var7.a(this.e);
         zaym var8 = new zaym();
         var8.a(7, 0, 0, 0);
         var8.a(this.e);
      }

      this.e.a((int)4148);
   }

   private void a(Area var1) throws Exception {
      if (var1 != null) {
         zaw var2 = new zaw(this.b, this.h.m());
         var2.a(var1);
         var2.a(this.e);
         zabz var3;
         if (var1.a()) {
            var3 = new zabz();
            var3.a(var1.getFillFormat());
            var3.a(this.e);
         } else if (var2.b()) {
            var3 = new zabz();
            var3.a(var1);
            var3.a(this.e);
         }

      }
   }

   private void a(short var1) throws Exception {
      this.b(var1);
      zbsv var2 = new zbsv(this.b);
      var2.a((ChartFrame)this.d.getChartArea());
      var2.a((zqa)this.e);
      this.e.a((int)4147);
      zavg var3 = new zavg(false);
      var3.a((zqa)this.e);
      if (this.d.getChartArea().getAutoScaleFont()) {
         int var4 = 0;
         ChartArea var5 = this.d.getChartArea();
         zbi var6;
         switch(var1) {
         case 2:
            if (var5.g() == null && var5.h() != -1) {
               var4 = var5.h();
            } else if (this.d.B().size() > 0) {
               var6 = (zbi)this.d.B().get(0);
               var4 = var6.d;
            }
            break;
         case 3:
            if (var5.g() == null && var5.a() != -1) {
               var4 = var5.a();
            } else if (this.d.B().size() > 1) {
               var6 = (zbi)this.d.B().get(1);
               var4 = var6.d;
            }
         }

         this.a((Font)null, var4, 0, (ArrayList)null);
      } else {
         this.a(this.d.getChartArea().g(), this.d.getChartArea().h(), 0, (ArrayList)null);
      }

      this.e.c(4177);
      this.e.c(8);
      this.e.c(256);
      this.e.a((int)0);
      this.e.c(0);
      if (var1 == 2 && this.d.getChartArea().b != null) {
         zayl var8 = new zayl();
         var8.a();
         var8.a(this.e);
         zbsu var7 = new zbsu();
         var7.a(this.d.getChartArea().b);
         var7.a(this.e);
         zaym var9 = new zaym();
         var9.a(2, 0, 0, 0);
         var9.a(this.e);
      }

      this.e.a((int)4148);
   }

   private void b(short var1) throws Exception {
      this.e.c(4132);
      this.e.c(2);
      this.e.a(var1);
   }

   private static void b(Chart var0) {
   }
}
